<?php
/*
 * @Description    : 龙远验证码
 * @Version        : 1.0.0
 * @Author         : QianLong
 * @Date           : 2020-10-29 15:53:35
 * @LastEditors    : QianLong
 * @LastEditTime   : 2022-05-13 16:29:36
 */

namespace app\common\service;

class DragonCaptcha
{
    public function check($data,$appId,$secret)
    {
        $params = array();
        $params["appId"] = $appId;
        $params["token"] = $data['token'];
        $params['sign'] = md5($data['token'].$secret);
        $url = "https://libs.21ds.cn/verify/RotateCaptcha/check";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        /* 设置返回结果为流 */
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        /* 设置超时时间*/
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        /* 设置通信方式 */
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/x-www-form-urlencoded'));
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
        $result = curl_exec($ch);
        return json_decode($result,true);
    }
}
